import React, { Component } from 'react'

export default class Addstu extends Component {
    handleAdd = () => {
        let {nameInput,ageInput,sexInput} = this;
        let name = nameInput.value;
        let age = ageInput.value;
        let sex = sexInput.checked?'male':'female';
        this.props.addStu({name,age,sex});
        nameInput.value='';ageInput.value='';
    }
    setNameRef = (ele) => {
        this.nameInput=ele
    }
    setAgeRef = (ele) => {
        this.ageInput=ele
    }
    getSex = (ele) => {
        this.sexInput=ele;
    }
    render() {
        return (
            <div>
                <h1>增加学生</h1>
                <p><label>姓名： </label><input ref={this.setNameRef} type="text" name="" /></p>
                <p><label>年龄： </label><input ref={this.setAgeRef} type="text" name="" /></p>
                <p><label htmlFor='sex'>性别：</label>男<input ref={this.getSex} type='radio' name="sex" defaultChecked/>女<input type="radio" name="sex" /></p>
                <button onClick={this.handleAdd}>增加</button>
            </div>
        )
    }

}
